local more1__zhongyong = fk.CreateSkill {
  name = "more1__zhongyong",
}

Fk:loadTranslationTable{
  ["more1__zhongyong"] = "忠勇",
  [":more1__zhongyong"] = "每回合各限一次，你不于摸牌阶段获得牌时，你可以展示至多体力上限张手牌并令这些牌视为【杀】且不计入手牌上限。"..
  "你造成或受到伤害时，你可以将任意张牌交给一名角色并令这些牌视为【杀】。"..
  "每回合准备阶段开始时，你可以将至多体力上限张【杀】置于牌堆顶，然后摸等量张牌。"..
  "当这些牌你全部失去时，你将手牌调整至体力上限。",

  ["#more1__zhongyong-show"] = "你可以展示至多 %arg 张手牌，令这些牌视为【杀】且不计入手牌上限。",
  ["#more1__zhongyong-give"] = "你可以将任意张牌交给一名角色并令这些牌视为【杀】。",
  ["#more1__zhongyong-move"] = "你可以将至多 %arg 张【杀】置于牌堆顶，然后摸等量张牌。",

  ["@@more1__zhongyong-inhand"] = "忠勇",

  ["$more1__zhongyong1"] = "",
  ["$more1__zhongyong2"] = ""
}

more1__zhongyong:addEffect(fk.AfterCardsMove, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(more1__zhongyong.name) and player:usedEffectTimes(self.name, Player.HistoryTurn) == 0 then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Card.PlayerHand and move.to.phase ~= Player.Draw and not move.to:isNude() and not move.to.dead then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = player.maxHp,
      include_equip = false,
      prompt = "#more1__zhongyong-show:::"..player.maxHp,
      skill_name = more1__zhongyong.name,
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    player:showCards(cards)
    for _, id in ipairs(cards) do
      room:setCardMark(Fk:getCardById(id), "@@more1__zhongyong-inhand", 1)
    end
  end,
})

--不计入手牌上限。
more1__zhongyong:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return player:hasSkill(more1__zhongyong.name) and card:getMark("@@more1__zhongyong-inhand") > 0
  end,
})
--"你造成或受到伤害时，你可以将任意张牌交予一名角色并令这些牌视为【杀】。"

local spec = {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(more1__zhongyong.name) and player:usedEffectTimes(self.name, Player.HistoryTurn) == 0 and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = 1,
      max_card_num = 999,
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      skill_name = more1__zhongyong.name,
      prompt = "#more1__zhongyong-give",
      cancelable = true,
    })
    if #to > 0 and #cards > 0 then
      room:sortByAction(to)
      event:setCostData(self, {tos = to, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    local to = event:getCostData(self).tos[1]
    room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, more1__zhongyong.name, nil, true, player)
    for _, id in ipairs(cards) do
      room:setCardMark(Fk:getCardById(id), "@@more1__zhongyong-inhand", 1)
    end
  end,
}
more1__zhongyong:addEffect(fk.Damage, spec)
more1__zhongyong:addEffect(fk.Damaged, spec)


--"每回合准备阶段开始时，你可以将至多体力上限张【杀】置于牌堆顶，然后摸等张牌。"..
more1__zhongyong:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(more1__zhongyong.name) and target.phase == Player.Start and
    player:usedEffectTimes(self.name, Player.HistoryTurn) == 0 and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = player.maxHp,
      include_equip = false,
      pattern = "slash",
      prompt = "#more1__zhongyong-move:::"..player.maxHp,
      skill_name = more1__zhongyong.name,
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    if #cards == 1 then
      room:moveCards({
        ids = cards,
        from = player,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = more1__zhongyong.name,
        proposer = player,
      })
    else
      local result = room:askToGuanxing(player, {
        cards = cards,
        bottom_limit = { 0, 0 },
        skill_name = more1__zhongyong.name,
        skip = true,
      })
      room:moveCards({
        ids = table.reverse(result.top),
        from = player,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = more1__zhongyong.name,
        proposer = player,
      })
    end
    room:drawCards(player, #cards, more1__zhongyong.name)
  end,
})
--  "当这些牌你全部失去时，你将手牌调整至体力上限。",

more1__zhongyong:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(more1__zhongyong.name, true) and not player.dead and not table.find(player:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@more1__zhongyong-inhand") > 0
    end) then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              local card = Fk:getCardById(info.cardId)
              if card:getMark("@@more1__zhongyong-inhand") > 0  then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getHandcardNum() - player.maxHp
    if n < 0 then
      player:drawCards(n, player.name)
    elseif n > 0 then
      room:askToDiscard(target, {
        min_num = n,
        max_num = n,
        include_equip = false,
        skill_name = player.name,
        cancelable = false,
      })
    end
  end,
})

--视为【杀】
more1__zhongyong:addEffect("filter", {
  mute = true,
  card_filter = function(self, card, player)
    return card:getMark("@@more1__zhongyong-inhand") > 0
  end,
  view_as = function(self, player, card)
    return Fk:cloneCard("slash", card.suit, card.number)
  end,
})


return more1__zhongyong
